package com.zz.TimeAdd;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;

public class Test {
    public static void main(String args[]){
        //1.获取本地日期对象（不可变对象）
        LocalDate ld = LocalDate.now();//年 月 日
        System.out.println(ld);

        //2.获取日期对象中的信息
        int year = ld.getYear();//年
        int month = ld.getMonthValue();//月（1-12）
        int day = ld.getDayOfMonth();//日
        int dayOfYear = ld.getDayOfYear();//一年中的第几天
        int dayOfWeek = ld.getDayOfWeek().getValue();//星期几
        System.out.println(year);
        System.out.println(dayOfWeek);
        System.out.println(dayOfYear);

        //3.直接修改某个信息：withYear,withMonth,withDayOfMonth,withDayOfYear
        LocalDate ld2 = ld.withYear(2099);
        System.out.println(ld2);

        //4.把某个信息价多少：plusYears,plusMonths,plusDays,plusWeeks
        LocalDate ld3 = ld.plusMonths(3);
        System.out.println(ld3);

        //5.把某个减多少，minusYears,minusMonths,minusDays,minusWeeks
        LocalDate ld4 = ld.minusYears(1);
        System.out.println(ld4);

        //6.获取指定日期的LocalDate对象， public static LocalDate of(int year, int month, int day)
        LocalDate ld5 = LocalDate.of(2089, 12, 13);
        LocalDate ld6 = LocalDate.of(2089, 12, 13);
        System.out.println(ld5);

        //7.判断2个日期对象，是否相等个，在前还是在后：equals isBefore isAfter
        System.out.println(ld5.equals(ld6));
        System.out.println(ld5.isAfter(ld));
        System.out.println(ld5.isBefore(ld));

        /**
         *  LocalDateTime可以转换成LocalDate、LocalTime
         *  public localDate toLocalDate()
         *  public localTime toLocalTime()
         *  public static LocalDateTime of(LocalDate date, LocalTime time)
         */
        LocalDateTime ldt = LocalDateTime.now();
        LocalDate ld7 = ldt.toLocalDate();
        LocalTime lt = ldt.toLocalTime();
        LocalDateTime ldt1 = LocalDateTime.of(ld7, lt);

    }
}
